using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DTO
{
	/// <summary> 
	///Author: nnamthach@gmail.com 
	/// <summary>
	
    public class OrderProductInfo
    {
		#region Local Variable
		public enum Field
		{
			ID,
			OrderProducts,
			ProductID,
			Quantity,
			Price
		}
		private Int32 _ID;
		private String _OrderProducts;
		private Int64 _ProductID;
		private Int32 _Quantity;
		private Double _Price;
		
		public Int32 ID{	get{ return _ID;} set{_ID = value;} }
		public String OrderProducts{	get{ return _OrderProducts;} set{_OrderProducts = value;} }
		public Int64 ProductID{	get{ return _ProductID;} set{_ProductID = value;} }
		public Int32 Quantity{	get{ return _Quantity;} set{_Quantity = value;} }
		public Double Price{	get{ return _Price;} set{_Price = value;} }
		
        #endregion LocalVariable
        
        #region Constructor
		public OrderProductInfo()
		{
			_ID = 0;
			_OrderProducts = "";
			_ProductID = 0;
			_Quantity = 0;
			_Price = 0;
		}
		public OrderProductInfo(
		Int32 ID,
		String OrderProducts,
		Int64 ProductID,
		Int32 Quantity,
		Double Price
		)
		{
			_ID = ID;
			_OrderProducts = OrderProducts;
			_ProductID = ProductID;
			_Quantity = Quantity;
			_Price = Price;
		}
		public OrderProductInfo(DataRow dr)
		{
			if (dr != null)
			{
				_ID = dr[Field.ID.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.ID.ToString()]);
				_OrderProducts = dr[Field.OrderProducts.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.OrderProducts.ToString()]);
				_ProductID = dr[Field.ProductID.ToString()] == DBNull.Value?0:Convert.ToInt64(dr[Field.ProductID.ToString()]);
				_Quantity = dr[Field.Quantity.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.Quantity.ToString()]);
				_Price = dr[Field.Price.ToString()] == DBNull.Value?0:Convert.ToDouble(dr[Field.Price.ToString()]);
			}
		}
		public OrderProductInfo(OrderProductInfo objEntr)
		{			
			_ID = objEntr.ID;			
			_OrderProducts = objEntr.OrderProducts;			
			_ProductID = objEntr.ProductID;			
			_Quantity = objEntr.Quantity;			
			_Price = objEntr.Price;			
		}
        #endregion Constructor
        
        #region InitTable
		public DataTable ToDataTable()
		{
			DataTable dt = new DataTable("OrderProduct");
			dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn(Field.ID.ToString(), typeof(Int32)),
				new DataColumn(Field.OrderProducts.ToString(), typeof(String)),
				new DataColumn(Field.ProductID.ToString(), typeof(Int64)),
				new DataColumn(Field.Quantity.ToString(), typeof(Int32)),
				new DataColumn(Field.Price.ToString(), typeof(Double))
			});
			return dt;
		}
		public DataRow ToDataRow(DataTable dt)
		{
			DataRow row = dt.NewRow();
			row[Field.ID.ToString()] = _ID;
			row[Field.OrderProducts.ToString()] = _OrderProducts;
			row[Field.ProductID.ToString()] = _ProductID;
			row[Field.Quantity.ToString()] = _Quantity;
			row[Field.Price.ToString()] = _Price;
			return row;
		}
        #endregion InitTable
    }
}
